<?php
//1. 跨域设置
header("access-control-allow-origin:*");
//2. 引入数据库
include_once("./utils/db.php");
include_once("./utils/functions.php");

//3. 编写sql语句,?是占位符
$insertSql = "insert into xk_course(coursename,departmentid,credit,period,content) values(?,?,?,?,?)";
//4. 接收前端传递的数据
$courseName = $_POST["coursename"];
$departmentid = $_POST["departmentid"];
$credit = $_POST["credit"];
$period = $_POST["period"];
$content = $_POST["content"];

//5.使用获取到的值，对占位符进行替换

$stmt = mysqli_prepare($conn, $insertSql);

$stmt->bind_param("siiis", $courseName, $departmentid, $credit, $period, $content);

$result = [];
if ($stmt->execute()) {
  $result = ["code" => 200, "msg" => '数据插入成功'];
} else {
  $result = ["code" => 0, "msg" => '数据插入失败'];
}
//6. 输出
echo json_encode($result, JSON_UNESCAPED_UNICODE);
